package com.lifo.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author Administrator
 * @date 2018/2/28 0028
 */
public class PropertiesSingleton {
    private static final Logger LOGGER = LoggerFactory.getLogger(PropertiesSingleton.class);
    private static volatile PropertiesSingleton instance = null;
    private static Properties properties = new Properties();

    static {
        File file = new File(Thread.currentThread().getContextClassLoader().getResource("huifv.properties").getFile());
        try {
            InputStream inputStream = new FileInputStream(file);
            properties.load(inputStream);
            LOGGER.info("properties资源文件成功加载到内存");
        } catch (IOException e) {
            LOGGER.error("properties资源文件初始化失败，您将无法获取有关微信的资源");
            e.printStackTrace();
        }

    }

    private PropertiesSingleton() {
    }

    /**
     * 单例的双重校验锁机制 begin
     */
    public static synchronized PropertiesSingleton newInstance() {
        if (instance == null) {
            synchronized (PropertiesSingleton.class) {
                if (instance == null) {
                    instance = new PropertiesSingleton();
                }
            }
        }
        return instance;
    }

    /**
     * 单例的双重校验锁机制 end
     */


    public Properties getProperties() {
        return properties;
    }

}
